package inutan.game;

import inutan.common.inner.GameCodec;
import inutan.common.inner.protocol.InnerProtocol;
import inutan.common.manager.GatewayManager;
import inutan.game.storage.ApplicationStorageLoadEvent;
import org.ricks.boot.Ricks;
import org.ricks.common.ModularContext;
import org.ricks.common.conf.RicksPropertiesLoader;
import org.ricks.common.event.EventBus;
import org.ricks.net.DataCodecKit;
import org.ricks.protocol.Protocol;
import org.ricks.protocol.ProtocolManager;

import java.util.Set;
import java.util.stream.Collectors;

public class GameRun {

    public static void main(String[] args) {
        DataCodecKit.setDataCodec(new GameCodec());
        ModularContext.me().scan(Set.of("inutan.game","inutan.common.config.datasource", "inutan.common.entity","inutan.common.inner.protocol"));
        RicksPropertiesLoader.loadingProperties();
        Set<Class<?>> classes = ModularContext.me().projectClasses();
        Set<Class<?>> protocolClasses = classes.stream().filter(c -> c.isAnnotationPresent(Protocol.class)).collect(Collectors.toSet());
        ProtocolManager.initProtocolAuto(protocolClasses);
        Ricks.run(GameBootstrap.class);
        EventBus.me().publish(new ApplicationStorageLoadEvent(null)); //发布加载策划数据事件
        GatewayManager.me().start(new InnerProtocol(), new GameHandler());
    }
}
